﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using static Sirius.SiriusAPI.SiriusAPI_Delegates;
using Sirius.OpenAPI;
using Sirius.SystemDll;

namespace Sirius.SiriusAPI
{
    public class SiriusApiManager
    {
        public static SiriusAPI_Struct SiriusAPI;
        public static InitSiriusAPI SiriusAPI_Init;
        public static void InitSiriusApi(IntPtr SiriusAPI_instance)
        {
            //获取SiriusAPI.dll路径
            string SiriusApiPath = $"{AppDomain.CurrentDomain.SetupInformation.ApplicationBase }" + "SiriusAPI.dll";

            //加载到内存

            //判断SiriusAPI是否加载成功
            if ((int)SiriusAPI_instance == 0)
                return;
            SiriusAPI_Init = Marshal.GetDelegateForFunctionPointer<InitSiriusAPI>(kernel32.GetProcAddress(SiriusAPI_instance, "InitApi"));
            SiriusAPI.sendMessage = openAPI.sendMessage;
            SiriusAPI.getBotInfo = openAPI.getBotInfo;
            SiriusAPI.getGuildList = openAPI.getGuildList;
            SiriusAPI.getGuildInfo = openAPI.getGuildInfo;
            SiriusAPI.getChannelList=openAPI.getChannelList;

            SiriusAPI.createChannel = openAPI.createChannel;
            SiriusAPI.setChannelInfo = openAPI.setChannelInfo;
            SiriusAPI.deleteChannel = openAPI.deleteChannel;
            SiriusAPI.createGuildRole = openAPI.createGuildRole;
            SiriusAPI.getGuildRoleList = openAPI.getGuildRoleList;

            SiriusAPI.setGuildRole = openAPI.setGuildRole;
            SiriusAPI.deleteGuildRole = openAPI.deleteGuildRole;
            SiriusAPI.addRoleMember = openAPI.addRoleMember;
            SiriusAPI.removeRoleMember = openAPI.removeRoleMember;
            SiriusAPI.getUserChannelPermissions = openAPI.get_userChannelPermissions;

            SiriusAPI.getChannelRolePermissions = openAPI.get_ChannelRolePermissions;
            SiriusAPI.setUserChannelPermissions = openAPI.set_userChannelPermissions;
            SiriusAPI.setChannelRolePermissions = openAPI.set_ChannelRolePermissions;
            SiriusAPI.getMessageByMsgId = openAPI.getMessageByMsg_Id;
            SiriusAPI.RollBack_Message = openAPI.RollBack_Message;

            SiriusAPI.create_PrivateMessage = openAPI.createPrivateMessage;
            SiriusAPI.send_PrivateMessage = openAPI.send_PrivateMessage;
            SiriusAPI.RollBack_PrivateMessage = openAPI.RollBack_PrivateMessage;
            SiriusAPI.no_Speak = openAPI.No_Speak;
            SiriusAPI.no_SpeakByUser = openAPI.No_SpeakByUser;

            SiriusAPI.create_Notice = openAPI.create_Notice;
            SiriusAPI.delete_Notice = openAPI.delete_Notice;
            SiriusAPI.addPinseMessage = openAPI.addPinsMessage;
            SiriusAPI.deletePinsMessage= openAPI.deletePinsMessage;
            SiriusAPI.getPinsMessage = openAPI.getPinsMessage;

            SiriusAPI.getScheduleList = openAPI.getSchedulesList;
            SiriusAPI.getScheduleInfo = openAPI.getScheduleInfo;
            SiriusAPI.create_Schedule = openAPI.create_Schedule;
            SiriusAPI.edit_Schedule= openAPI.edit_Schedule;
            SiriusAPI.delete_Schedule= openAPI.delete_Schedule;

            SiriusAPI.sendEmoji = openAPI.sendEmoji;
            SiriusAPI.deleteEmoji = openAPI.deleteEmoji;
            SiriusAPI.getChannelInfo = openAPI.getChannelInfo;
            SiriusAPI.LogOut = Sirius.Log.Log.LogOut;
            SiriusAPI.removeGuildMember  = openAPI.removeGuildMember;

            SiriusAPI.getMemberList = openAPI.getMemberList;
            SiriusAPI.getMemberListByRole = openAPI.getMemberListByRole;
            SiriusAPI.getMemberInfo = openAPI.getMemberInfo;
            SiriusAPI.sendImgMessage = openAPI.sendImgMessage;
            SiriusAPI_Init(SiriusAPI);
        }
    }

    public struct SiriusAPI_Struct
    {
        public Api_sendMessage sendMessage;
        public Api_getBotInfo getBotInfo;
        public Api_getGuildList getGuildList;
        public Api_getGuildInfo getGuildInfo;
        public Api_getChannelList getChannelList;

        public Api_createChannel createChannel;
        public Api_setChannelInfo setChannelInfo;
        public Api_deleteChannel deleteChannel;
        public Api_createGuildRole createGuildRole;
        public Api_getGuildRoleList getGuildRoleList;

        public Api_setGuildRole setGuildRole;
        public Api_deleteGuildRole deleteGuildRole;
        public Api_addRoleMember addRoleMember;
        public Api_removeRoleMember removeRoleMember;
        public Api_get_userChannelPermissions getUserChannelPermissions;

        public Api_get_ChannelRolePermissions getChannelRolePermissions;
        public Api_set_userChannelPermissions setUserChannelPermissions;
        public Api_set_ChannelRolePermissions setChannelRolePermissions;
        public Api_getMessageByMsg_Id getMessageByMsgId;
        public Api_RollBack_Message RollBack_Message;

        public Api_create_PrivateMessage create_PrivateMessage;
        public Api_send_PrivateMessage send_PrivateMessage;
        public Api_RollBack_PrivateMessage RollBack_PrivateMessage;
        public Api_No_Speak no_Speak;
        public Api_No_SpeakByUser no_SpeakByUser;

        public Api_create_Notice create_Notice;
        public Api_delete_Notice delete_Notice;
        public Api_addPinseMessage addPinseMessage;
        public Api_deletePinsMessage deletePinsMessage;
        public Api_getPinsMessage getPinsMessage;

        public Api_getScheduleList getScheduleList;
        public Api_getScheduleInfo getScheduleInfo;
        public Api_create_Schedule create_Schedule;
        public Api_edit_ScheduleInfo edit_Schedule;
        public Api_delete_Schedule delete_Schedule;

        public Api_sendEmoji sendEmoji;
        public Api_deleteEmoji deleteEmoji;
        public Api_getChannelInfo getChannelInfo;
        public Api_LogOut LogOut;
        public Api_removeGuildMember removeGuildMember;

        public Api_getMemberList getMemberList;
        public Api_getMemberListByRole getMemberListByRole;
        public Api_getMemberInfo getMemberInfo;
        public Api_sendImgMessage sendImgMessage;
    }
    public class SiriusAPI_Delegates
    {
        public delegate void InitSiriusAPI(SiriusAPI_Struct data);
        
        public delegate string? Api_sendMessage(string channel_Id, string? msg = "", string? embedMsg = "", string? arkMsg = "", string? message_referenceMsg = "", string? image_Url = "", string? msg_Id = "", string?event_id="",string? markDown = "");
        public delegate string? Api_getBotInfo();
        public delegate string? Api_getGuildList(string? before, string? after, string? limit);
        public delegate string? Api_getGuildInfo(string Guild_Id);
        public delegate string? Api_getChannelList(string Guild_Id);

        public delegate string? Api_createChannel(string guild_id, string? name, string? type, string? sub_type, string position, string? parent_id, string? private_type, string private_user_ids, string? speak_permission, string? application_id);
        public delegate string? Api_setChannelInfo(string? channel_Id, string? name, string? position, string? parent_id, string? private_type, string? speak_permission);
        public delegate bool Api_deleteChannel(string channel_Id);
        public delegate string? Api_getGuildRoleList(string guild_Id);
        public delegate string? Api_createGuildRole(string guild_Id, string? name, string? color, string? hoist);

        public delegate string? Api_getChannelInfo(string? channel_Id);
        public delegate string? Api_setGuildRole(string guild_Id, string role_Id, string? name, string? color, string? hoist);
        public delegate bool  Api_deleteGuildRole(string guild_Id, string role_Id);
        public delegate bool Api_addRoleMember(string guild_Id, string role_Id, string user_Id, string? channel_Id);
        public delegate bool Api_removeRoleMember(string guild_Id, string role_Id, string user_Id, string? channel_Id);

        public delegate string? Api_get_userChannelPermissions(string channel_Id, string user_Id);
        public delegate string? Api_get_ChannelRolePermissions(string channel_Id, string role_Id);
        public delegate bool  Api_set_userChannelPermissions(string channel_Id, string user_Id, string? add, string? remove);
        public delegate bool Api_set_ChannelRolePermissions(string channel_Id, string role_Id, string? add, string? remove);
        public delegate string? Api_getMessageByMsg_Id(string channel_Id, string msg_Id);

        public delegate bool Api_RollBack_Message(string channel_Id, string msg_Id, byte hide= 0);
        public delegate string? Api_create_PrivateMessage(string user_id, string guild_id);
        public delegate string? Api_send_PrivateMessage(string guild_Id, string? content, string? embed, string? ark, string? message_reference, string? image_Url, string? msg_Id, string? markdown);
        public delegate bool Api_RollBack_PrivateMessage(string guild_id, string message_id, byte hide = 0);
        public delegate bool Api_No_Speak(string guild_id, string? mute_end_timestamp, string? mute_seconds);

        public delegate bool Api_No_SpeakByUser(string guild_id, string user_id, string? mute_end_timestamp, string? mute_seconds);
        public delegate string? Api_create_Notice(string guild_id, string? msg_id, string? channel_id, string? announces_type, string? recommend_channels);
        public delegate bool Api_delete_Notice(string guild_id, string msg_id);
        public delegate string? Api_addPinseMessage(string channel_id, string msg_id);
        public delegate bool Api_deletePinsMessage(string channel_id, string msg_id);

        public delegate string? Api_getPinsMessage(string channel_id);
        public delegate string? Api_getScheduleList(string channel_id, string since);
        public delegate string? Api_getScheduleInfo(string? channel_id, string schedule_id);
        public delegate string? Api_create_Schedule(string channel_id, string name, string? description, string start_timestamp, string end_timestamp, string jump_channel_id, string? remind_type = "0");
        public delegate string? Api_edit_ScheduleInfo(string channel_id, string schedule_id, string name, string? description, string start_timestamp, string end_timestamp, string jump_channel_id, string? remind_type = "0");
        
        public delegate bool Api_delete_Schedule(string channel_id, string schedule_id);
        public delegate bool Api_sendEmoji(string channel_id, string message_id, string type, string emoji_Id);
        public delegate bool Api_deleteEmoji(string channel_id, string message_id, string type, string emoji_Id);
        public delegate void Api_LogOut(string role, string logData);
        public delegate bool Api_removeGuildMember(string guild_id, string user_id, byte add_blacklist = 0, string delete_history_msg_days = "0");
        
        public delegate string Api_getMemberList(string guild_id, string after, string limit);
        public delegate string Api_getMemberListByRole(string guild_id, string role_id,string start_index,string limit);
        public delegate string Api_getMemberInfo(string guild_id, string user_id);
        public delegate string Api_sendImgMessage(string channel_Id, string msg, string msg_id, string imgPath);
  }
}
